/**
 * SpringMVC restful 风格
 * 分组控制器，控制关于分组的一些业务逻辑操作
 * @author yanwl
 * @date 2015-07-13
 */
package com.company.example.controller;

import com.company.example.core.util.RedisUtil;
import com.company.example.model.pojo.Group;
import com.company.example.service.GroupService;
import com.company.example.service.GroupServiceTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import redis.clients.jedis.JedisCluster;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * 控制器注解 请求映射注解 controller 代表类是控制器 restcontroller 代表类是控制器， 所有的方法 都是ajax方法
 * 
 * @author yanwl
 *
 */
@Controller
@RequestMapping("/group")
public class GroupController {
	/**
	 * 注入 业务逻辑层
	 */
	@Autowired
	private GroupService groupService;
	
//	@Autowired
	private JedisCluster jc;
	
	@Autowired
	private RedisUtil redisUtil;
	
	@Autowired
	private GroupServiceTest groupServiceTest;
	
	/**
	 * @return 测试页面 
	 * @throws Exception
	 */
	@RequestMapping(value = "/index.htm", method = RequestMethod.GET)
	public ModelAndView index() throws Exception {
		ModelAndView mav = new ModelAndView();
		mav.setViewName("test");
		return mav;
	}

	/**
	 * @return 分组列表页面
	 * @throws Exception
	 */
	@RequestMapping(value = "/test.htm/{id}", method = RequestMethod.GET)
	@ResponseBody
//	@MethodLog(remark = "分组查询")
	public void test(@PathVariable Integer id,String name) throws Exception {
		for(int i = 2; i < 3; i++) {
			Group g = new Group();
			g.setCreateTime(new Date());
			g.setName("分组"+i);
			g.setNum(BigDecimal.valueOf(i));
			groupServiceTest.insert(g);
		}
		/*Group group = groupService.selectGroupByPrimaryKey(3);
		group.setName("分组");
		groupService.updateGroup(group);*/
		
		List<Group> groups = groupServiceTest.selectAllObjects();
		for (Group group : groups) {
			System.out.println(group.getName() + "--" + group.getNum());
		}
		
		/*groupService.deleteGroup(id);*/
		 
	}
	
	
	/**
	 * @return 集群测试
	 * @throws Exception
	 */
	@RequestMapping(value = "/test.htm", method = RequestMethod.GET)
	@ResponseBody
	public void jedisClusterTest(String name,String age) throws Exception {
		/*System.out.println("name:" + jc.get("name"));
		System.out.println("age:" + jc.get("age"));
		System.out.println("******************************");
		jc.set("name", name);
		jc.set("age", age);
		System.out.println("name:" + jc.get("name"));
		System.out.println("age:" + jc.get("age"));*/
		
		
		/*System.out.println("name:" + redisUtil.get("name"));
		System.out.println("age:" + redisUtil.get("age"));
		System.out.println("******************************");
		redisUtil.set("name", name);
		redisUtil.set("age", age);
		System.out.println("name:" + redisUtil.get("name"));
		System.out.println("age:" + redisUtil.get("age"));*/
	}
}
